package com.fourthGroup.controller;

import com.fourthGroup.service.TradeService;
import com.fourthGroup.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/trade")
@Slf4j
public class TradeController {

    @Autowired
    private TradeService tradeService;

    /**
     * 使用优惠券下单
     */
    @PostMapping("/order/coupon")
    public Result<String> createOrderWithCoupon(
            @RequestParam Integer userId,
            @RequestParam Integer productId,
            @RequestParam Integer number,
            @RequestParam Long couponId) {
        log.info("用户{}使用优惠券{}购买商品{}，数量: {}", userId, couponId, productId, number);
        return tradeService.createOrderWithCoupon(userId, productId, number, couponId);
    }
} 